import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
import axios from 'axios'
// 导入ECharts
import * as echarts from 'echarts';

// 创建Vue应用实例
const app = createApp(App)

// 注册Element Plus图标
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
  app.component(key, component)
}

// 配置axios
axios.defaults.baseURL = ''
axios.defaults.timeout = 60000

// 请求拦截器
axios.interceptors.request.use(
  (config) => {
    return config
  },
  (error) => {
    return Promise.reject(error)
  }
)

// 响应拦截器
axios.interceptors.response.use(
  (response) => {
    return response
  },
  (error) => {
    console.error('HTTP请求错误:', error)
    return Promise.reject(error)
  }
)

// 全局挂载axios和echarts
app.config.globalProperties.$axios = axios
app.config.globalProperties.$echarts = echarts;

// 使用插件
app.use(router)
app.use(ElementPlus, { size: 'default' })

// 挂载应用
app.mount('#app')
